import fs from 'fs';
import { message } from './utils.js';

class DltIndexController {

    index() {
        let list = [];
        fs.readdirSync('./data/dlt/order/').forEach(file => {
            list.push(file);
        })
        return message(list);
    }

    read(id) {
        let filename = './data/dlt/order/' + id + '.json';
        if (!fs.existsSync(filename)) {
            return message(null, '数据不存在', 404);
        }
        let data = fs.readFileSync(filename).toString();
        if (data) {
            data = JSON.parse(data.trim());
        }
        return message(data);
    }

    save() {

    }
}

export default DltIndexController;